<?php

namespace Coldwind;

/**
 * @author ZXZ <zxz054321@163.com>
 */
class Url {

    /**
     * 拼装参数字符串
     * @param array $param
     */
    public static function assembleParam($param) {
        $paramStr = '';
        foreach ($param as $key => $value) {
            if (!empty($paramStr))
                $paramStr.='&';

            $paramStr.=$key . '=' . $value;
        }

        return $paramStr;
    }

    /**
     * 拼装URL字符串
     * @param string $baseUrl
     * @param mixed $param
     */
    public static function assembleUrl($baseUrl, $param = '') {
        $paramStr = is_array($param) ? self::assembleParam($param) : $param;

        if (!strstr($baseUrl, '?'))
            $baseUrl.='?';

        return $baseUrl . $paramStr;
    }

}
